package lancooUpLoad;

import com.example.hyznbk.presenter.PaperDef;
import com.example.hyznbk.presenter.presenter_interface.IBaseReviewPresenter;
import com.example.hyznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import testPaperWrong.WrongQuesPaperActivity;

/**
 * Created by Administrator on 2017/9/5/005.
 */

public class SaveLearnedWrongQuesPresenter implements IBaseReviewPresenter {

    private ILoadPaperView view;
    private int ModelFrom;
    private boolean isFromExit = false;

    public SaveLearnedWrongQuesPresenter(ILoadPaperView view, int modelFrom) {
        this.view = (ILoadPaperView) view;
        this.ModelFrom = modelFrom;
    }

    @Override
    public void getData(boolean isShowLoading) {
        //  if (isShowLoading) view.showLoading();
        HttpOnNextListener<String> httpOnNextListener = new HttpOnNextListener<String>() {


            @Override
            public void onNext(String saveWrongQuesEntityResult) {
                if(saveWrongQuesEntityResult.equals("true")){

//                    showShort("数据保存成功");

                }else{
//                    showShort("数据保存失败!结果信息为："+saveWrongQuesEntityResult);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                //view.showNetError();
            }
        };

        SaveLearnedWrongQuesParam api = new SaveLearnedWrongQuesParam(httpOnNextListener, (WrongQuesPaperActivity)view);

        if(ModelFrom== PaperDef.FROM_BASE_REVIEW_WRONG){
            api.setSaveLearnedWrongQues(DataPackage.getSaveLearnedWrongQuesJson(UserInfo.StuId,UserInfo.SubjectId,UserInfo.StageNo,
                    PaperInfor.WrongQuesID,0,PaperInfor.WrongQuesTotalItemCount));
        }else if(ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG){
            api.setSaveLearnedWrongQues(DataPackage.getSaveLearnedWrongQuesJson(UserInfo.StuId,UserInfo.SubjectId,UserInfo.StageNo,
                    PaperInfor.WrongQuesID,1,PaperInfor.WrongQuesTotalItemCount));
        }
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }

    public void getData(boolean isShowing ,boolean isFromExit){
        this.isFromExit = isFromExit;
        getData(isShowing);
    }

}